package org.ielse.frame;

import org.ielse.frame.util.BaseUtil;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;

public class BaseService extends Service {

	private final IBinder mBinder = new LocalBinder();

	public class LocalBinder extends Binder {
		public BaseService getService() {
			return BaseService.this;
		}
	}

	@Override public IBinder onBind(Intent intent) {
		return mBinder;
	}

	@Override public void onCreate() {
		super.onCreate();
		logd("onCreate()");
	}

	@Override public int onStartCommand(Intent intent, int flags, int startId) {
		logd("onStartCommand()");
		return super.onStartCommand(intent, flags, startId);
	}

	@Override public void onDestroy() {
		logd("onDestroy()");
		super.onDestroy();
	}

	public void logi(String text) {
		if (C.settings.DEBUG && !TextUtils.isEmpty(text)) Log.i(getClass().getSimpleName(), text);
	}

	public void logd(String text) {
		if (C.settings.DEBUG && !TextUtils.isEmpty(text)) Log.d(getClass().getSimpleName(), text);
	}

	public void logw(String text) {
		if (C.settings.DEBUG && !TextUtils.isEmpty(text)) Log.w(getClass().getSimpleName(), text);
	}

	public void loge(String text) {
		if (C.settings.DEBUG && !TextUtils.isEmpty(text)) Log.e(getClass().getSimpleName(), text);
	}

	public void startActivity(Class<?> targetActivity, Object... params) {
		startActivity(targetActivity, BaseUtil.initBundle(params));
	}

	public void startActivity(Class<?> targetActivity, Bundle bundle) {
		Intent intent = new Intent(this, targetActivity);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtras(bundle);
		startActivity(intent);
	}
}
